//
//  FreeListAllocator.h
//  MemoryManager
//
//  Created by Bram Buurlage on 7/2/12.
//  Copyright (c) 2012 Bram Buurlage. All rights reserved.
//

#ifndef MemoryManager_FreeListAllocator_h
#define MemoryManager_FreeListAllocator_h

#include "Allocator.h"
#include "PowerOfTwoArea.h"

class ListHeader;
class FreeListAllocator: public Allocator
{
public:
    FreeListAllocator();
    virtual ~FreeListAllocator();
    
    virtual void        printFragmentation();
    
    virtual const Area* alloc(int wanted);
    virtual void        free(const Area*);
    
    virtual void        setSize(int size);
    
private:
    double      baselog;
    int         minpower;
    int         maxpower;
    int         nextbase;
    ListHeader** headers;
};

class ListHeader
{
public:
    ListHeader(int size);
    ~ListHeader();
    
    void printFragmentation();

    Area* alloc(int& nextbase, int maxsize);
    void free(PowerOfTwoArea* a);
    
private:
    int size;
    PowerOfTwoArea* firstFreeArea;
};



#endif
